var do_App = sm("do_App");
var do_Page = sm("do_Page");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var urlUser = require("url/user");
var httpSilence = require("helper/httpSilence");
var openHelper = require("helper/open");
var drawUrl = require("url/draw");

// UI
var headerAout = ui("headerAout");
var aLayoutRoot = ui("aLayoutRoot");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");

// andriod返回键
do_Page.on("back", function() {
	do_App.closePage();
});

//andriod返回键
do_Page.on("result", function(data) {
	if(null!=data&&data.fromPage=="draw_index"){
		addLoginFunc();
	}
});
// 左上角-返回
var headerLeft = ui(addheader + ".headerLeft");
// 右上角-
var headerRight = ui(addheader + ".headerRight");
headerRight.visible = false;
headerLeft.on("touch", function() {
	do_App.closePage()
});
header.bindData(hashdata);
hashdata.addData({
	"labelTitle" : "抽奖",
})
header.refreshData();
// 页面装载完成后，开始初始化工作
do_Page.on("loaded", function() {
	//addLoginFunc();
});

var do_LinearLayout_1=ui("do_LinearLayout_1");
/*圈币*/
/*var addDrawSt = do_LinearLayout_1.add("drawSt", "source://view/reuse/mutiLabel3.ui",0,0);
var drawSt = ui("drawSt");
drawSt.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "我的分享抽奖",
    "labelTipsVisible":true,
    "labelTips":"",
    "imgForwardVisible": false
});
drawSt.refreshData();
var drawlabeLTips=ui(addDrawSt+".labelTips");*/

var addCoupon = do_LinearLayout_1.add("coupon", "source://view/reuse/mutiLabel3.ui",0,0);
var coupon = ui("coupon");
coupon.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "我的中奖",
    "labelTipsVisible":true,
    "labelTips":"查看我的中奖"
});
coupon.refreshData();


/*var addLottery = do_LinearLayout_1.add("lottery", "source://view/reuse/mutiLabel3.ui",0,0);
var lottery = ui("lottery");
lottery.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "我的中奖",
    "labelTipsVisible":true,
    "labelTips":"查看中奖历史记录"
});
lottery.refreshData();*/

var drawCount=0;
var userId;
/*ui(addDrawSt).on("touch", "", 3000, function(data, e) {
	if(drawCount>0){
		loadLottery();
	}
});*/
ui(addCoupon).on("touch", function(data, e) {
	openHelper.open("source://view/coupon/manage/list.ui");
});
/*ui(addLottery).on("touch", function(data, e) {
	openHelper.open("source://view/lottery/manage/list.ui");
});*/
function addLoginFunc(){
	httpSilence.post(urlUser.url.base.get, {}, function(data) {
		userId=data.userValueVo.id;
		drawCount=data.userValueVo.drawCount;
		drawlabeLTips.text=data.userValueVo.drawCount;
	});
}
function loadLottery(){
	httpSilence.post(drawUrl.url.base.detail, {}, function(data) {
		if(null!=data.drawBaseVo){
			var drawId=data.drawBaseVo.id;
			var rewardNames=[];
			var imgs=[];
			for (var i = 0; i < data.items.length; i++) {
				var item=data.items[i];
				rewardNames.push(item.drawItemName);
				imgs.push(item.drawItemImg);
				
			}
			openHelper.open("source://view/lottery/index.ui",{userDrawList:data.userDrawList,type:3,bizzId:userId,drawId:drawId,rewardNames:rewardNames,imgs:imgs});
		}
	});
}
